package com.manger.utils;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class FileTransferable implements Transferable {

    private String[] filePaths;

    private int index = 0;

    public FileTransferable(String... filePaths) {
        this.filePaths = filePaths;
    }

    @Override
    public DataFlavor[] getTransferDataFlavors() {
        return new DataFlavor[]{DataFlavor.javaFileListFlavor}; // 支持文件列表的flavor
    }

    @Override
    public boolean isDataFlavorSupported(DataFlavor flavor) {
        return DataFlavor.javaFileListFlavor.equals(flavor);
    }

    @Override
    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
        if (!DataFlavor.javaFileListFlavor.equals(flavor)) {
            throw new UnsupportedFlavorException(flavor);
        }
        List<File> files = new ArrayList<>();
        for (String filePath : filePaths) {
            File file = new File(filePath);
            files.add(file);
        }
        return files; // 返回文件列表
    }
}
